<!--
 * @Description: 商家任务纠纷详情
 * @Author: liyujie
 * @Date: 2021/05/10
 * @Last Modified by: liyujie
 * @Last Modified time: 2021/05/10
-->
<template>
    <div class="wrapper">
        <div class="content-wrapper">
            <!-- header -->
            <div class="header">
                <div class="header-title">
                    任务纠纷详情
                </div>
            </div>
            <!-- /header -->
            <div class="status-view">
                <template v-if="formData.verify === 0">
                    <div class="status-text warning">待审核</div>
                    <div class="status-desc-text">{{ formData.user_type === 1 ? '用户' : '商家' }}发起申诉，请尽快审核~</div>
                </template>
                <template v-if="formData.verify === 1">
                    <div class="status-text success">审核通过</div>
                    <div class="status-desc-text">处理结果：{{ formData.verify_reason }}</div>
                </template>
                <template v-if="formData.verify === -1">
                    <div class="status-text danger">审核不通过</div>
                    <div class="status-desc-text">驳回原因：{{ formData.verify_reason }}</div>
                </template>
            </div>
            <div class="dispute-view">
                <div class="dispute-content">
                    <el-form label-width="82px">
                        <el-form-item label="发起人：">
                            {{ formData.user_type === 1 ? formData.apply_student_name : formData.apply_company_name }}
                        </el-form-item>
                        <el-form-item label="申诉原因：">
                            {{ formData.content }}
                        </el-form-item>
                        <el-form-item label="申诉图片：">
                            <div class="image-list">
                                <el-image
                                    v-for="(url,imgIndex) in formData.images"
                                    :key="imgIndex"
                                    :src="url"
                                    class="image"
                                    @click="showPreview(formData.images, imgIndex)"
                                >
                                    <div
                                        slot="error"
                                        class="image-slot"
                                    >
                                        <i class="el-icon-picture-outline"/>
                                    </div>
                                </el-image>
                            </div>
                        </el-form-item>
                    </el-form>
                </div>
            </div>
            <el-form>
                <div class="form-wrapper">
                    <div class="form-title">
                        任务基本信息
                    </div>
                    <el-form inline>
                        <el-row>
                            <el-col :span="8">
                                <el-form-item label="公司名称：">
                                    {{ formData.company_name }}
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item
                                    label="任务名称："
                                    class="is-required"
                                >
                                    {{ formData.task_title }}
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item
                                    label="任务时间："
                                    class="is-required"
                                >
                                    {{ formData.start_time * 1000 | dateFormatter('yyyy/MM/dd') }} - {{ formData.end_time * 1000 | dateFormatter('yyyy/MM/dd') }}
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="8">
                                <el-form-item
                                    label="任务总数："
                                    class="is-required"
                                >
                                    {{ formData.all_count }}个
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item
                                    label="奖励金额："
                                    class="is-required"
                                >
                                    {{ formData.task_price }}元/个
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="任务链接：">
                                    <el-link
                                        :href="formData.task_url"
                                        target="_blank"
                                    >
                                        {{ formData.task_url ? formData.task_url : '--' }}
                                    </el-link>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>
                    <el-form label-width="82px">
                        <el-form-item
                            label="任务介绍："
                            style="width: 678px;"
                        >
                            {{ formData.task_intro }}
                        </el-form-item>
                        <el-form-item
                            label="考核标准："
                            style="width: 678px;"
                        >
                            {{ formData.task_standard ? formData.task_standard : '--' }}
                        </el-form-item>
                        <el-form-item
                            label="任务步骤："
                            class="bold"
                        >
                            <div
                                class="form-content"
                                style="margin-left: 0;margin-top: 8px; padding: 24px 66px"
                            >
                                <div
                                    v-for="(item, index) in formData.guide"
                                    :key="index"
                                    class="form-content-step"
                                >
                                    <div class="form-content-step-title">步骤{{ numberChinese(index + 1) }}</div>
                                    <el-form-item label="步骤内容：">
                                        {{ item.content }}
                                    </el-form-item>
                                    <el-form-item label="步骤图片：">
                                        <div class="image-list">
                                            <el-image
                                                v-for="(url,imgIndex) in item.images"
                                                :key="imgIndex"
                                                :src="url"
                                                class="image"
                                                @click="showPreview(item.images, imgIndex)"
                                            >
                                                <div
                                                    slot="error"
                                                    class="image-slot"
                                                >
                                                    <i class="el-icon-picture-outline"/>
                                                </div>
                                            </el-image>
                                        </div>
                                    </el-form-item>
                                </div>
                            </div>
                        </el-form-item>
                    </el-form>
                </div>
                <div
                    class="form-wrapper"
                    style="border: 0"
                >
                    <div class="form-title">
                        反馈内容
                    </div>
                    <div class="form-content">
                        <custom-form-data :data="formData.submit_config"/>
                    </div>
                </div>
            </el-form>
            <div class="operating-view">
                <el-button
                    size="medium"
                    v-if="formData.verify"
                    @click="handleRoute('shopTaskDisputeList')"
                >
                    返回
                </el-button>
                <el-button
                    size="medium"
                    v-if="!formData.verify"
                    @click="showVerifyDialog(-1)"
                >
                    申诉驳回
                </el-button>
                <el-button
                    size="medium"
                    type="primary"
                    v-if="!formData.verify"
                    @click="showVerifyDialog(1)"
                >
                    申诉成立
                </el-button>
            </div>
        </div>
        <!-- 审核驳回 -->
        <reject-dialog
            ref="rejectDialog"
            :visible.sync="rejectDialog"
            placeholder="请输入拒绝原因"
            :maxlength="100"
            @confirm="handleVerify(dispute_no, -1, $event)"
        />
        <!-- 申诉成立 -->
        <reject-dialog
            ref="confirmDialog"
            :visible.sync="confirmDialog"
            title="申诉成立"
            placeholder="请输入处理结果"
            :maxlength="100"
            @confirm="handleVerify(dispute_no, 1, $event)"
        />
        <!-- 图片预览 -->
        <img-preview ref="preview" />
    </div>
</template>

<script>
import { back } from '@/mixin/back';
import RejectDialog from "@/components/dialog/reject-dialog";
import { numberChinese } from "@/assets/js/utils";
import ImgPreview from "@/components/common/img-preview";
import CustomFormData from "@/components/common/custom-form-data";

export default {
    name: 'ShopTaskReceiveDetail',
    mixins: [back],
    components: {CustomFormData, ImgPreview, RejectDialog},
    data() {
        return {
            dispute_no: '',
            formData: {},
            rejectDialog: false,
            confirmDialog: false,
            authResult: {}
        };
    },
    computed: {},
    watch: {},
    filters: {},
    mounted() {
        let query = this.$route.query;

        this.$store.commit('SET_HEADER', [{title: "APP后台"}, {title: '工作'}, {title: '商家远程任务'}, {title: '任务纠纷列表', path: '/student/shop-task-dispute-list'}, {title: '纠纷详情'}]);
        this.authResult = this.$route.meta.authResult;
        this.dispute_no = query.dispute_no;
        this.getDetailData();
    },

    methods: {
        numberChinese,
        /**
         * @description 获取数据
         */
        getDetailData() {
            let params = {
                dispute_no: this.dispute_no
            };

            this.$post('/student/task_stuagent_dispute%5Cget', params, res => {
                if (res.code === 1) {
                    this.formData = res.data;
                } else {
                    this.$notify({
                        title: '提示',
                        message: res.msg,
                        type: 'warning'
                    });
                }
            });
        },

        /**
         * 路由跳转
         * @param routeName
         * @param query
         */
        handleRoute(routeName, query) {
            this.$router.push({
                name: routeName,
                query
            });
        },

        /**
         * 预览图片
         * @param   {String}    images      //单图预览
         * @param   {Array}     images      //多图预览
         * @param index
         */
        showPreview(images, index) {
            if (images && Object.prototype.toString.call(images) == '[object String]') {
                this.$refs.preview.show([
                    images
                ]);
            } else if (images && Object.prototype.toString.call(images) == '[object Array]') {
                this.$refs.preview.show(images, index);
            } else {
                this.$message({
                    type: 'warning',
                    message: '图片类型错误'
                });
            }
        },

        /**
         * 显示审核操作弹窗
         * @param action -1拒绝 1 通过
         */
        showVerifyDialog(action) {
            // 通过
            if (action === 1) {
                this.confirmDialog = true;
            } else {
                this.rejectDialog = true;
            }
        },

        /**
         * 审核
         * @param dispute_no
         * @param verify
         * @param verify_reason
         */
        handleVerify(dispute_no, verify, verify_reason) {
            if(!this.authResult.auth_verify) {
                this.$notify({
                    title: '提示',
                    message: '请联系管理员添加权限',
                    type: 'warning',
                    duration: 2000
                });
                return false;
            }
            let params = {
                dispute_no,
                verify,
                verify_reason
            };

            this.$post('/student/task_stuagent_dispute%5Caudit', params, resp => {
                if (resp.code === 1) {
                    this.$notify({
                        title: '提示',
                        message: '操作成功',
                        duration: 2000,
                        type: 'success'
                    });
                    this.getDetailData();
                    this.handleRoute('shopTaskDisputeList');
                } else {
                    this.$notify({
                        title: '提示',
                        message: resp.msg,
                        duration: 2000,
                        type: 'warning'
                    });
                }
            });
        }
    }
};
</script>

<style lang="less" scoped>
.wrapper {
    width: 100%;

    .content-wrapper {
        display: flex;
        height: calc(100% - 24px);
        flex-direction: column;
        position: relative;
        margin: 12px;
        background: #fff;
        box-sizing: border-box;
        overflow-y: auto;
        &::-webkit-scrollbar {
            width: 6px;
        }

        /*header*/

        .header {
            height: 68px;
            padding: 24px;
            box-sizing: border-box;
            box-shadow: 0px -1px 0px 0px #F0F2F5;
            display: flex;
            align-items: center;
            justify-content: space-between;

            .header-title {
                color: #333333;
                font-size: 20px;
                height: 20px;
                font-weight: 500;
                position: relative;
                margin: 24px 0;
            }
        }
        .status-view {
            display: flex;
            flex-direction: column;
            height: 64px;
            padding-left: 56px;
            flex-shrink: 0;
            .status-text {
                font-size: 16px;
                font-family: PingFangSC-Medium, PingFang SC;
                font-weight: 500;
                margin-bottom: 12px;
                &.warning {
                    color: #FFB726;
                }
                &.success {
                    color: #2FBDB3;
                }
                &.danger {
                    color: #F95B56;
                }
            }
            .status-desc-text {
                font-size: 12px;
                font-family: PingFangSC-Regular, PingFang SC;
                font-weight: 400;
                color: #999999;
            }
        }
        .dispute-view {
            display: flex;
            flex-direction: column;
            padding: 0 56px;
            border-bottom: 1px solid #F0F2F5;
            flex-shrink: 0;
            .dispute-content {
                background: #FBFBFB;
                border: 1px solid #EEEEEE;
                padding: 24px 32px;
                margin-bottom: 24px;
            }
        }
        .form-wrapper {
            padding: 32px 56px 0;
            border-bottom: 1px solid #E9E9E9;
            .form-title {
                font-size: 16px;
                font-family: PingFangSC-Semibold, PingFang SC;
                font-weight: 600;
                color: #333333;
                margin-bottom: 24px;
            }
            .form-content {
                padding: 24px 44px;
                background: #FBFBFB;
                border-radius: 2px;
                margin-bottom: 24px;
                margin-left: 82px;
                .form-content-step {
                    .form-content-step-title {
                        font-weight: 500;
                        color: #555555;
                        margin-bottom: 12px;
                        position: relative;
                        &::before {
                            content: "";
                            display: block;
                            width: 10px;
                            height: 10px;
                            border-radius: 50%;
                            background: #C2C2C2;
                            position: absolute;
                            left: -22px;
                            top: 50%;
                            transform: translateY(-50%);
                        }
                    }
                }
                .feedback-item {
                    display: flex;
                    font-size: 14px;
                    font-family: PingFangSC-Medium, PingFang SC;
                    font-weight: 500;
                    color: #333333;
                    margin-bottom: 16px;
                    line-height: 14px;
                    .feedback-item-content {
                        flex: 1;
                        .feedback-item-content-input {
                            display: flex;
                            align-items: center;
                            height: 36px;
                            background: #F2F2F2;
                            border-radius: 4px;
                            font-size: 14px;
                            font-family: PingFangSC-Regular, PingFang SC;
                            font-weight: 400;
                            color: #666666;
                            padding: 10px 12px;
                            line-height: 22px;
                        }
                        .video-wrapper {
                            margin-top: 16px;
                            width: 102px;
                            height: 102px;
                            border-radius: 4px;
                            cursor: pointer;
                            margin-right: 12px;
                            margin-bottom: 4px;
                            position: relative;
                            display: flex;
                            align-items: center;
                            justify-content: center;
                            overflow: hidden;
                            .video-icon {
                                position: absolute;
                                width: 32px;
                                z-index: 1;
                            }
                        }
                    }
                }

                &.feedback {
                    background: #fff;
                    border: 1px solid #F79038;
                }
            }
        }
        .operating-view {
            padding: 32px 138px 52px;
            .el-button {
                width: 120px;
                margin-right: 36px;
            }
        }
        .image-list {
            margin-top: 8px;
            .image {
                width: 102px;
                height: 102px;
                border-radius: 4px;
                cursor: pointer;
                margin-right: 12px;
                margin-bottom: 4px;
            }
        }
    }
    /deep/ .el-form {
        .el-form-item {
            margin-bottom: 6px;
        }
        .el-form-item__label {
            color: #555;
        }
        .bold {
            .el-form-item__label {
                font-size: 14px;
                font-family: PingFangSC-Medium, PingFang SC;
                font-weight: 500;
                color: #333333;
            }
        }
        .focus {
            .el-form-item__label {
                font-size: 14px;
                font-family: PingFangSC-Regular, PingFang SC;
                font-weight: 400;
                color: #F79038;
            }
        }
        .el-form-item__content {
            line-height: 24px;
            margin-top: 8px;
            color: #999;
        }
        .is-required {
            .el-form-item__label {
                &:before {
                    content: "*";
                    display: inline-block;
                    color: #F56C6C;
                    margin-right: 4px;
                }
            }
        }
    }
    /deep/ .el-dialog__header {
        padding-top: 10px;
        box-shadow:0 1px 0 0 rgba(233,233,233,1);
        display: flex;
        align-items: center;
        background: #FAFAFA;
        border-radius: 4px 4px 0 0;
        .el-dialog__title {
            font-weight: 500;
            color: #333;
            font-size: 14px;
        }
        .el-icon-close:before {
            color: rgb(194,194,194);
            font-size: 17px;
            font-weight: bold;
        }
        .el-dialog__headerbtn {
            top: 14px;
        }
    }
    .dialog-footer {
        display: flex;
        justify-content: center;
    }
    /deep/ .el-textarea__inner {
        resize: none;
    }
}
</style>
